home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1994-12-21 | 5.5 KB | 157 lines | [TEXT/.Ob4] |
- Syntax10.Scn.Fnt
- StampElems
- Alloc
- 21 Dec 94
- Syntax10i.Scn.Fnt
- Syntax10b.Scn.Fnt
- MODULE PictElems; (* HM
- IMPORT Sys, Display, Files, Fonts, Input, Printer, Texts, TextFrames, TextPrinter, Oberon, Out, SYSTEM;
- (*--- pictures*)
- Ptr = LONGINT;
- Handle = LONGINT;
- Picture = RECORD [Sys.align68K]
- picSize: INTEGER;
- picFrame: Sys.Rect;
- data: ARRAY 100000 OF LONGINT (*picture data: not allocated in full size*)
- END;
- PicHandle = POINTER TO RECORD [Sys.align68K]
- p: POINTER TO Picture
- END;
- DrawPicture: PROCEDURE (myPicture: Handle; dstRect: Sys.Rect);
- KillPicture: PROCEDURE (myPicture: Handle);
- (*--- scrap manager*)
- CONST
- PICT = 50494354H; (*"PICT"*)
- GetScrap: PROCEDURE (handle, type: LONGINT; VAR offset: LONGINT): LONGINT;
- PutScrap: PROCEDURE (length, theType: LONGINT; src: Ptr): LONGINT;
- ZeroScrap: PROCEDURE (): LONGINT;
- (*--- element*)
- CONST
- pixel = LONG(TextFrames.Unit); ppixel = LONG(TextPrinter.Unit);
- left = 2; middle = 1; right = 0;
- Elem = POINTER TO ElemDesc;
- ElemDesc = RECORD (Texts.ElemDesc)
- pic: PicHandle;
- len: LONGINT
- END;
- PROCEDURE CopyElem (e: Elem);
- VAR err: LONGINT;
- BEGIN
- err := ZeroScrap();
- err := PutScrap(e.len, PICT, SYSTEM.VAL(Ptr, e.pic.p));
- ASSERT(err = 0)
- END CopyElem;
- PROCEDURE PasteElem (e: Elem);
- VAR dummy, h, pos: LONGINT; ph: PicHandle; t: Texts.Text; r: Sys.Rect;
- BEGIN
- h := Sys.NewHandle(0);
- e.len := GetScrap(h, PICT, dummy);
- IF e.len > 0 THEN
- ph := SYSTEM.VAL(PicHandle, h);
- NEW(e.pic); SYSTEM.NEW(e.pic.p, e.len);
- SYSTEM.MOVE(SYSTEM.ADR(ph.p^), SYSTEM.ADR(e.pic.p^), e.len);
- r := e.pic.p.picFrame; KillPicture(h);
- e.W := (r.right - r.left) * pixel; e.H := (r.bottom - r.top) * pixel;
- t := Texts.ElemBase(e);
- IF t # NIL THEN
- pos := Texts.ElemPos(e);
- TextFrames.NotifyDisplay(t, Texts.replace, pos, pos + 1)
- END
- ELSE Out.String("-- no picture in clipboard$")
- END PasteElem;
- (* GetDsr should not be necessary if the error in TextPrinter is corrected *)
- PROCEDURE GetDsr (f: Display.Frame; pos: LONGINT; fnt: Fonts.Font; VAR dsr: INTEGER);
- VAR p: TextFrames.Parc; beg: LONGINT;
- BEGIN
- IF f = NIL THEN
- IF fnt = NIL THEN dsr := 0 ELSE dsr := - fnt.minY END
- ELSE
- TextFrames.ParcBefore(f(TextFrames.Frame).text, pos, p, beg);
- dsr := SHORT(p.dsr DIV TextFrames.Unit)
- END GetDsr;
- PROCEDURE Handler* (e: Texts.Elem; VAR m: Texts.ElemMsg);
- VAR e1: Elem; r: Sys.Rect; x, y, dsr: INTEGER; keys: SET;
- BEGIN
- WITH e: Elem DO
- WITH
- m: TextFrames.DisplayMsg DO
- IF ~m.prepare THEN
- r.left := m.X0; r.right := r.left + SHORT(e.W DIV pixel);
- r.bottom := Display.Height - m.Y0; r.top := r.bottom - SHORT(e.H DIV pixel);
- DrawPicture(SYSTEM.VAL(Handle, e.pic), r)
- END
- | m: TextPrinter.PrintMsg DO
- IF ~m.prepare THEN
- GetDsr(NIL, m.pos, m.fnt, dsr);
- r.left := m.X0; r.right := r.left + SHORT(e.W DIV ppixel);
- r.bottom := Printer.PageHeight - m.Y0 - SHORT(dsr*pixel DIV ppixel);
- r.top := r.bottom - SHORT(e.H DIV ppixel);
- DrawPicture(SYSTEM.VAL(Handle, e.pic), r)
- END
- | m: Texts.IdentifyMsg DO
- m.mod := "PictElems"; m.proc := "Alloc"
- | m: Texts.FileMsg DO
- IF m.id = Texts.load THEN
- Files.ReadNum(m.r, e.len);
- NEW(e.pic); SYSTEM.NEW(e.pic.p, e.len); Files.ReadBytes(m.r, e.pic.p^, e.len);
- r := e.pic.p.picFrame;
- e.W := (r.right - r.left) * pixel; e.H := (r.bottom - r.top) * pixel
- ELSIF m.id = Texts.store THEN
- Files.WriteNum(m.r, e.len); Files.WriteBytes(m.r, e.pic.p^, e.len)
- END
- | m: Texts.CopyMsg DO
- NEW(e1); Texts.CopyElem(e, e1); e1.len := e.len; e1.pic := e.pic; m.e := e1
- | m: TextFrames.TrackMsg DO
- IF middle IN m.keys THEN
- REPEAT Input.Mouse(keys, x, y); m.keys := m.keys + keys;
- Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
- UNTIL keys = {};
- IF m.keys = {middle, right} THEN CopyElem(e)
- ELSIF m.keys = {middle, left} THEN PasteElem(e)
- END
- END
- ELSE
- END
- END Handler;
- PROCEDURE Alloc*;
- VAR e: Elem;
- BEGIN NEW(e); e.handle := Handler; Texts.new := e
- END Alloc;
- PROCEDURE Insert*;
- VAR e: Elem; insert: TextFrames.InsertElemMsg;
- BEGIN
- NEW(e); e.handle := Handler; PasteElem(e);
- IF e.len > 0 THEN
- insert.e := e; Oberon.FocusViewer.handle(Oberon.FocusViewer, insert)
- END Insert;
- PROCEDURE Copy*;
- VAR t: Texts.Text; beg, end, time: LONGINT; r: Texts.Reader; e: Texts.Elem;
- BEGIN
- Oberon.GetSelection(t, beg, end, time);
- IF time >= 0 THEN
- Texts.OpenReader(r, t, beg);
- REPEAT Texts.ReadElem(r) UNTIL r.eot OR (Texts.Pos(r) > end) OR (r.elem IS Elem);
- IF ~r.eot & (Texts.Pos(r) <= end) THEN CopyElem(r.elem(Elem)) END
- END;
- END Copy;
- PROCEDURE Paste*;
- VAR t: Texts.Text; beg, end, time: LONGINT; r: Texts.Reader; e: Texts.Elem;
- BEGIN
- Oberon.GetSelection(t, beg, end, time);
- IF time >= 0 THEN
- Texts.OpenReader(r, t, beg);
- REPEAT Texts.ReadElem(r) UNTIL r.eot OR (Texts.Pos(r) > end) OR (r.elem IS Elem);
- IF ~r.eot & (Texts.Pos(r) <= end) THEN PasteElem(r.elem(Elem)) END
- END;
- END Paste;
- BEGIN
- Sys.Assign("GetScrap", SYSTEM.ADR(GetScrap));
- Sys.Assign("PutScrap", SYSTEM.ADR(PutScrap));
- Sys.Assign("ZeroScrap", SYSTEM.ADR(ZeroScrap));
- Sys.Assign("DrawPicture", SYSTEM.ADR(DrawPicture));
- Sys.Assign("KillPicture", SYSTEM.ADR(KillPicture));
- END PictElems.
- PictElems.Insert
- System.Free PictElems ~
- System.DeleteFiles xxx ~
-